﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace AUV5.Web.Manage
{
    public partial class InformManage : PageBaseBackend
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bindInform();
            }
        }

        //绑定
        private void bindInform()
        {
            Model.NetPager pager = new Model.NetPager();
            pager.TableName = "InformList";
            pager.PrimaryKey = "ListID";
            pager.Order = "CreateDate desc,ListID desc";
            pager.SortType = (int)Common.Enum.SortType.Multi;
            pager.Where = "";
            pager.PageSize = AspNetPager1.PageSize;
            pager.PageIndex = AspNetPager1.CurrentPageIndex;
            repInform.DataSource = BLL.InformListBLL.Instance.GetPagedList(pager);
            repInform.DataBind();
            AspNetPager1.RecordCount = pager.TotalCount;
        }

        //换页
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            bindInform(); 
        }


        protected void repInform_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            string informid = ((HiddenField)e.Item.FindControl("hfListID")).Value;
            HtmlAnchor refInfo = (HtmlAnchor)e.Item.FindControl("refInfo");
            LinkButton lbtnHandle = (LinkButton)e.Item.FindControl("lbtnHandle");
            Model.InformList inform = BLL.InformListBLL.Instance.GetDetail(informid);
            if (inform != null)
            { 
                if(!string.IsNullOrEmpty(inform.ToUser))
                {
                    refInfo.InnerText = "查看被举报用户";
                    refInfo.HRef= "/"+BLL.UserInfoBLL.Instance.GetUserName(inform.ToUser);
                    lbtnHandle.Text = "禁用用户";
                }
                else if(!string.IsNullOrEmpty(inform.RefMessageID))
                {
                    refInfo.InnerText = "查看被举报消息";
                    lbtnHandle.Text = "禁用用户";
                }
                else if(!string.IsNullOrEmpty(inform.RefServiceID))
                {
                    refInfo.InnerText = "查看被举报服务";
                    refInfo.HRef = "/Pages/ServiceDetail.aspx?serviceID="+inform.RefServiceID;
                    lbtnHandle.Text = "删除服务";
                }
                else if(!string.IsNullOrEmpty(inform.RefRequestID))
                {
                    refInfo.InnerText = "查看被举报需求";
                    refInfo.HRef = "/";
                    lbtnHandle.Text = "删除需求";
                }
                else
                {
                    refInfo.InnerText = "添加信息时出现异常";
                }
            }
        }
    }
}